/**
 * 文件名：****.java
 * 版权：Copyright Lightkit All Rights Reserved.
 * 描述：*****
 */
package com.lightkits.wms.domain.mainpage;


import com.lightkits.framework.common.utility.object.ObjectUtil;
import com.lightkits.framework.soa.hzero.executor.ServiceExecutor;
import com.lightkits.wms.dto.mainpage.QueryWorkerInfoRequestType;
import com.lightkits.wms.dto.mainpage.QueryWorkerInfoResponseType;
import com.lightkits.wms.domain.mainpage.service.WorkerInfoDomainService;
import com.lightkits.wms.dto.mainpage.model.ResourceInfoDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * QueryWorkerInfoExecutor
 *
 * @author menxiao.wu@hand-china.com
 * Created on 2019-02-20 20:19
 */
@Component
public class QueryWorkerInfoExecutor
        implements ServiceExecutor<QueryWorkerInfoRequestType, QueryWorkerInfoResponseType> {
    private final WorkerInfoDomainService service;

    @Autowired
    public QueryWorkerInfoExecutor(WorkerInfoDomainService service) {
        this.service = service;
    }

    @Override
    public QueryWorkerInfoResponseType service(QueryWorkerInfoRequestType request) {
        QueryWorkerInfoResponseType response = new QueryWorkerInfoResponseType();
        response.setSuccessful(true);

        String organizationId = request.getOrganizationId();
        String workerGroupCode = request.getWorkerGroupCode();

        if (ObjectUtil.isNullOrEmpty(organizationId)) {
            response.setSuccessful(false);
            response.setMessage("organizationId And workerGroupCode is required");
            return response;
        }

        List<ResourceInfoDTO> resourceInfoDTOS = service.listWorkerInfo(organizationId,
                workerGroupCode, request.getWorkerNumAndName());
        response.setResourceInfoDTOS(resourceInfoDTOS);

        //response.setPageDataCount(resourceInfoDTOS.size());
        return response;
    }
}
